##############################
## BLIS/Swayable: Key Stats ##
##############################

# File Description: 
# Uses data/packages from O_Data.R
# Replicates calculation of key stats from Fabric of Repair report (2025)
# Date Last Updated: 2 May 2025

##############################

### Calculating baseline support

# Reparations baseline support
df_bn_repbaseline_plot <- 
  df %>% 
  group_by(race_single) %>% 
  count(rep_baseline_categorical) %>% 
  mutate(Percentage = n/sum(n) * 100) %>% 
  rename(baseline_support = rep_baseline_categorical) %>% 
  add_column(Movement = "Reparations")

# Land Back baseline support
df_bn_landbackbaseline_plot <- 
  df %>% 
  group_by(race_single) %>% 
  count(landback_baseline_categorical) %>% 
  mutate(Percentage = n/sum(n) * 100) %>% 
  rename(baseline_support = landback_baseline_categorical) %>% 
  add_column(Movement = "Land Back")

# Merging baseline support dataframes
df_bn_baselinesupport_plot <- bind_rows(df_bn_repbaseline_plot, df_bn_landbackbaseline_plot)

# Viewing Baseline support
df_bn_baselinesupport_plot

### Calculating predictions by race and video treatment

# Movement regressions
land_back_support <- lm(Land.Back.Support ~ treatment*race + video_perception, df)
reparations_support <- lm(Reparations.Support ~ treatment*race + video_perception, df)

# Movement predictions
lb_preds <- ggpredict(land_back_support, terms = c("treatment", "race")) %>%
  mutate(outcome = "Land Back")
r_preds <- ggpredict(reparations_support, terms = c("treatment", "race")) %>%
  mutate(outcome = "Reparations")

# Merged predictions
support_preds <- rbind(lb_preds, r_preds)

# Black support for reparations with braided video
(support_preds$predicted[support_preds$x == "Both" & support_preds$group == "Black" & support_preds$outcome == "Reparations"] - support_preds$predicted[support_preds$x == "Control" & support_preds$group == "Black" & support_preds$outcome == "Reparations"]) / support_preds$predicted[support_preds$x == "Control" & support_preds$group == "Black" & support_preds$outcome == "Reparations"]

# Black support for landback with braided video
(support_preds$predicted[support_preds$x == "Both" & support_preds$group == "Black" & support_preds$outcome == "Land Back"] - support_preds$predicted[support_preds$x == "Control" & support_preds$group == "Black" & support_preds$outcome == "Land Back"]) / support_preds$predicted[support_preds$x == "Control" & support_preds$group == "Black" & support_preds$outcome == "Land Back"]

# Native support for reparations with braided video
(support_preds$predicted[support_preds$x == "Both" & support_preds$group == "Indigenous" & support_preds$outcome == "Reparations"] - support_preds$predicted[support_preds$x == "Control" & support_preds$group == "Indigenous" & support_preds$outcome == "Reparations"]) / support_preds$predicted[support_preds$x == "Control" & support_preds$group == "Indigenous" & support_preds$outcome == "Reparations"]

# Native support for landback with braided video
(support_preds$predicted[support_preds$x == "Both" & support_preds$group == "Indigenous" & support_preds$outcome == "Land Back"] - support_preds$predicted[support_preds$x == "Control" & support_preds$group == "Indigenous" & support_preds$outcome == "Land Back"]) / support_preds$predicted[support_preds$x == "Control" & support_preds$group == "Indigenous" & support_preds$outcome == "Land Back"]

# Black support for landback increase with reparations video
(support_preds$predicted[support_preds$x == "Reparations" & support_preds$group == "Black" & support_preds$outcome == "Land Back"] - support_preds$predicted[support_preds$x == "Control" & support_preds$group == "Black" & support_preds$outcome == "Land Back"]) / support_preds$predicted[support_preds$x == "Control" & support_preds$group == "Black" & support_preds$outcome == "Land Back"]

# Native support for reparations increase with landback video
(support_preds$predicted[support_preds$x == "Land Back" & support_preds$group == "Indigenous" & support_preds$outcome == "Reparations"] - support_preds$predicted[support_preds$x == "Control" & support_preds$group == "Indigenous" & support_preds$outcome == "Reparations"]) / support_preds$predicted[support_preds$x == "Control" & support_preds$group == "Indigenous" & support_preds$outcome == "Reparations"]

### Calculating predictions by race, partisanship, and video treatment

# Movement regressions
land_back_polrace <- lm(Land.Back.Support ~ race*summarized_party*treatment + video_perception, data = df) 
reparations_polrace <- lm(Reparations.Support ~ race*summarized_party*treatment + video_perception, data = df)

# Movement predictions
lb_pol <- ggpredict(land_back_polrace, terms = c("treatment", "race", "summarized_party")) %>%
  mutate(outcome = "Land Back")
r_pol <- ggpredict(reparations_polrace, terms = c("treatment", "race", "summarized_party")) %>%
  mutate(outcome = "Reparations")

# Merged predictions
full_preds_threeway <- rbind(lb_pol, r_pol)

# Native Democrats' support for landback with braided video
(full_preds_threeway$predicted[full_preds_threeway$x == "Both" & full_preds_threeway$group == "Indigenous" & full_preds_threeway$facet == "Democrat" & full_preds_threeway$outcome == "Land Back"] - full_preds_threeway$predicted[full_preds_threeway$x == "Control" & full_preds_threeway$group == "Indigenous" & full_preds_threeway$facet == "Democrat" & full_preds_threeway$outcome == "Land Back"]) / full_preds_threeway$predicted[full_preds_threeway$x == "Control" & full_preds_threeway$group == "Indigenous" & full_preds_threeway$facet == "Democrat" & full_preds_threeway$outcome == "Land Back"]

# Native Democrats' support for reparations increase with landback video
(full_preds_threeway$predicted[full_preds_threeway$x == "Both" & full_preds_threeway$group == "Indigenous" & full_preds_threeway$facet == "Democrat" & full_preds_threeway$outcome == "Reparations"] - full_preds_threeway$predicted[full_preds_threeway$x == "Control" & full_preds_threeway$group == "Indigenous" & full_preds_threeway$facet == "Democrat" & full_preds_threeway$outcome == "Reparations"]) / full_preds_threeway$predicted[full_preds_threeway$x == "Control" & full_preds_threeway$group == "Indigenous" & full_preds_threeway$facet == "Democrat" & full_preds_threeway$outcome == "Reparations"]

# Native Republicans' support for reparations increase with landback video
(full_preds_threeway$predicted[full_preds_threeway$x == "Land Back" & full_preds_threeway$group == "Indigenous" & full_preds_threeway$facet == "Republican" & full_preds_threeway$outcome == "Reparations"] - full_preds_threeway$predicted[full_preds_threeway$x == "Control" & full_preds_threeway$group == "Indigenous" & full_preds_threeway$facet == "Republican" & full_preds_threeway$outcome == "Reparations"]) / full_preds_threeway$predicted[full_preds_threeway$x == "Control" & full_preds_threeway$group == "Indigenous" & full_preds_threeway$facet == "Republican" & full_preds_threeway$outcome == "Reparations"]

# Black Democrats' support for Land Back increase with Reparations video
(full_preds_threeway$predicted[full_preds_threeway$x == "Reparations" & full_preds_threeway$group == "Black" & full_preds_threeway$facet == "Democrat" & full_preds_threeway$outcome == "Land Back"] - full_preds_threeway$predicted[full_preds_threeway$x == "Control" & full_preds_threeway$group == "Black" & full_preds_threeway$facet == "Democrat" & full_preds_threeway$outcome == "Land Back"]) / full_preds_threeway$predicted[full_preds_threeway$x == "Control" & full_preds_threeway$group == "Black" & full_preds_threeway$facet == "Democrat" & full_preds_threeway$outcome == "Land Back"]

# Black Democrats' support for Reparations increase with Braided video
(full_preds_threeway$predicted[full_preds_threeway$x == "Both" & full_preds_threeway$group == "Black" & full_preds_threeway$facet == "Democrat" & full_preds_threeway$outcome == "Reparations"] - full_preds_threeway$predicted[full_preds_threeway$x == "Control" & full_preds_threeway$group == "Black" & full_preds_threeway$facet == "Democrat" & full_preds_threeway$outcome == "Reparations"]) / full_preds_threeway$predicted[full_preds_threeway$x == "Control" & full_preds_threeway$group == "Black" & full_preds_threeway$facet == "Democrat" & full_preds_threeway$outcome == "Reparations"]

# Black Democrats' support for Land Back with Braided
(full_preds_threeway$predicted[full_preds_threeway$x == "Both" & full_preds_threeway$group == "Black" & full_preds_threeway$facet == "Democrat" & full_preds_threeway$outcome == "Land Back"] - full_preds_threeway$predicted[full_preds_threeway$x == "Control" & full_preds_threeway$group == "Black" & full_preds_threeway$facet == "Democrat" & full_preds_threeway$outcome == "Land Back"]) / full_preds_threeway$predicted[full_preds_threeway$x == "Control" & full_preds_threeway$group == "Black" & full_preds_threeway$facet == "Democrat" & full_preds_threeway$outcome == "Land Back"]

# Indigenous Democrats' support for Reparations with Braided
(full_preds_threeway$predicted[full_preds_threeway$x == "Both" & full_preds_threeway$group == "Indigenous" & full_preds_threeway$facet == "Democrat" & full_preds_threeway$outcome == "Reparations"] - full_preds_threeway$predicted[full_preds_threeway$x == "Control" & full_preds_threeway$group == "Indigenous" & full_preds_threeway$facet == "Democrat" & full_preds_threeway$outcome == "Reparations"]) / full_preds_threeway$predicted[full_preds_threeway$x == "Control" & full_preds_threeway$group == "Indigenous" & full_preds_threeway$facet == "Democrat" & full_preds_threeway$outcome == "Reparations"]

# Indigenous Republicans' support for Reparations with Reparations
(full_preds_threeway$predicted[full_preds_threeway$x == "Reparations" & full_preds_threeway$group == "Indigenous" & full_preds_threeway$facet == "Republican" & full_preds_threeway$outcome == "Reparations"] - full_preds_threeway$predicted[full_preds_threeway$x == "Control" & full_preds_threeway$group == "Indigenous" & full_preds_threeway$facet == "Republican" & full_preds_threeway$outcome == "Reparations"]) / full_preds_threeway$predicted[full_preds_threeway$x == "Control" & full_preds_threeway$group == "Indigenous" & full_preds_threeway$facet == "Republican" & full_preds_threeway$outcome == "Reparations"]
